/*
Author: Jason Bareswilt
Functionality: To allow the user to choose certain options for the game through a GUI
Version number: 0.0.7
Testers: needs to be tested
Date written: November 22nd 2011
Date tested: needs to be tested
*/
package disease;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import disease.RottingFlesh;

public class Options implements MouseListener
{
	public void optionsGUI()
	{
		System.out.println("Options");
		RottingFlesh.frame.getContentPane().removeAll();
		DrawingArea drawingArea = new DrawingArea();
		ButtonPanel buttonPanel = new ButtonPanel( drawingArea );
		DrawingArea panel = new DrawingArea(new ImageIcon("ZombiesRevBOptions.jpg").getImage());
		RottingFlesh.frame.addMouseListener(this);
		RottingFlesh.frame.getContentPane().add(panel);
		RottingFlesh.frame.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
		RottingFlesh.frame.setSize(450, 450);
		RottingFlesh.frame.setResizable(false);
		RottingFlesh.frame.setVisible(true);
	}

	static class ButtonPanel extends JPanel implements ActionListener
	{
		private static final long serialVersionUID = 1L;

		public ButtonPanel(DrawingArea drawingArea)
		{
			add( createButton("Main Menu", Color.RED) );
			add( createButton("Quit", Color.RED) );
			setBackground(Color.BLACK);
		}

		private JButton createButton(String text, Color background)
		{
			JButton button = new JButton(text);
			button.setBackground(background);
			button.addActionListener(this);
			UIManager.put("Button.select", Color.red);
			updateUI();
			return button;
		}

		public void actionPerformed(ActionEvent e)
		{
			
			if ("Main Menu".equals(e.getActionCommand()))
			{
				RottingFlesh.createAndShowGUI();
			}
			if ("Quit".equals(e.getActionCommand()))
			{
				System.exit(0);
			}
		}
	}

	static class DrawingArea extends JPanel
	{
		private static final long serialVersionUID = 1L;
		private static Image img;
		public DrawingArea(String filename)
		{
			this(new ImageIcon(img).getImage());
		}
		public DrawingArea(Image img)
		{
			DrawingArea.img = img;
			Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
			setPreferredSize(size);
			setMinimumSize(size);
			setMaximumSize(size);
			setSize(size);
			setLayout(null);
	    }
		public DrawingArea()
		{

		}

		public void paintComponent(Graphics g)
		{
			g.drawImage(img, 0, 0, null);
	      	Font smallFont = new Font("Serif", Font.BOLD, 14);
	      	Font largeFont = new Font("Serif", Font.BOLD, 20);
	      	g.setFont(largeFont);
	      	g.setColor(Color.red);
	      	g.drawString("Choose Game Difficulty", 130, 160);
	      	g.setFont(smallFont);
			Color transBlack = new Color(0,0,0,175);
			g.setColor(transBlack);
			g.fillRect(40, 200, 100, 25);
			g.fillRect(180, 200, 100, 25);
			g.fillRect(320, 200, 100, 25);
			g.fillRect(115, 250, 230, 125);//this is where the text goes inside of
			g.setColor(Color.red);
			if(RottingFlesh.difficulty == 1){
				//easy
				g.drawString("Money gains faster", 120, 270);
				g.drawString("Zombies are weaker", 120, 300);
				g.drawString("Prices are lower", 120, 330);
				g.drawString("Facilities are stronger", 120, 360);
			}else if(RottingFlesh.difficulty == 2){
				//medium
				g.drawString("Money gains at normal rate", 120, 270);
				g.drawString("Zombies have normal strength", 120, 300);
				g.drawString("Prices are average", 120, 330);
				g.drawString("Facilities have normal speed", 120, 360);
			}else if(RottingFlesh.difficulty == 3){
				//hard
				g.drawString("Money gains slower", 120, 270);
				g.drawString("Zombies are stronger", 120, 300);
				g.drawString("Prices are higher", 120, 330);
				g.drawString("Facilities are weaker", 120, 360);
			}else{
				System.out.println("We should not have a difficulty not equal to 1,2 or 3");
			}
			
			//Add drawStrings for the differences between
			//Hard Normal and Easy
			
			g.drawString("Hard", 70, 217);
			g.drawString("Normal", 204, 217);
			g.drawString("Easy", 350, 217);
			if (RottingFlesh.difficulty == 1)
			{
				g.drawRect(320, 200, 100, 25);
				g.drawRect(319, 201, 102, 23);
			}
			if (RottingFlesh.difficulty == 2)
			{
				g.drawRect(180, 200, 100, 25);
				g.drawRect(179, 201, 102, 23);
			}
			if (RottingFlesh.difficulty == 3)
			{
				g.drawRect(40, 200, 100, 25);
				g.drawRect(39, 201, 102, 23);
			}
			//(x, y, width, heighth)
			
//			super.paintComponent(g);
//
//			Color foreground = g.getColor();
//
//			g.setColor( Color.BLACK );
//
//			g.setColor( foreground );
		}
	}

	@Override
	public void mouseClicked(MouseEvent e1) 
	{
		if (e1.getX() > 40 && e1.getX() < 140 && e1.getY() > 225 && e1.getY() < 250)
		{
			RottingFlesh.difficulty = 3;
			RottingFlesh.frame.repaint();
		}
		
		else if (e1.getX() > 180 && e1.getX() < 280 && e1.getY() > 225 && e1.getY() < 250)
		{
			RottingFlesh.difficulty = 2;
			RottingFlesh.frame.repaint();
		}
		
		else if (e1.getX() > 320 && e1.getX() < 420 && e1.getY() > 225 && e1.getY() < 250)
		{
			RottingFlesh.difficulty = 1;
			RottingFlesh.frame.repaint();
		}
	}

	@Override
	public void mouseEntered(MouseEvent e1) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e1) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e1) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent e1) {
		// TODO Auto-generated method stub
		
	}
}